package com.woniu.controller;

import com.woniu.Result;
import com.woniu.pojo.ServiceType;
import com.woniu.service.IServiceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaohuang
 * @since 2022-11-17
 */
@RestController
@RequestMapping("/serviceType")
@Api(tags = "服务类型管理")
public class ServiceTypeController {

    @Autowired
    private IServiceTypeService service;

    @ApiOperation("查询所有")
    @GetMapping
    public Result<List<ServiceType>> findAll(){
        List<ServiceType> list = service.list();
        return Result.ok(list);
    }

    @ApiOperation("添加")
    @PostMapping
    public Result<String> save(@RequestBody ServiceType serviceType){
        boolean save = service.save(serviceType);
        return save ? Result.ok():Result.fail();
    }

    @ApiOperation("修改")
    @PutMapping
    public Result<String> update(@RequestBody ServiceType serviceType){
        boolean b = service.updateById(serviceType);
        return b ? Result.ok():Result.fail();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Result<String> save(@PathVariable Integer id){
        boolean b = service.removeById(id);
        return b ? Result.ok():Result.fail();
    }
}
